package com.gosophia.reportData.action;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.PropertyFilter;
import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.dataDictionary.dto.DataValueDTO;
import com.gosophia.dataDictionary.ws.DataDictionaryWebService;
import com.gosophia.flowFormManagement.dto.FlowFormDTO;
import com.gosophia.flowFormManagement.ws.FlowFormWebService;
import com.gosophia.reportData.bean.UserInfoBean;
import com.gosophia.reportData.dto.ReportDetailDTO;
import com.gosophia.reportData.ws.ReportDataSearchWebService;
import com.gosophia.taskManagement.dto.JobDTO;
import com.gosophia.taskManagement.dto.MissionDTO;
import com.gosophia.taskManagement.ws.TaskManagementWebService;
import com.gosophia.userManagement.dto.UserInfoDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 进入上报发起
 * 
 * @author tianchunyu
 */
@Controller
@Scope("prototype")
public class LaunchReportAction extends BaseSupportAction {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private ReportDataSearchWebService reportDataSearchWebService;
    
    @Autowired
    private UserManagementWebService userManagementWebService;
    
    @Autowired
    private TaskManagementWebService taskManagementWebService;

    @Autowired
    private DataDictionaryWebService dataDictionaryWebService ;
    
    @Autowired
    private FlowFormWebService flowFormWebService;

    private String userInfoDtosJson;
    
    private List<DataValueDTO> importanceList ;

    private List<FlowFormDTO> flowFormDtos;

    private Long jobId;
    
    private static final Long IMPORTANCE_ENTRYID = 1014L;
    //来源标记
    private String fromFlag;
    
    private MissionDTO missionDto;
    
    private ReportDetailDTO reportDetailDTO;
    
    @Override
    public String _execute() throws Exception {
        //获取重要程度列表
        importanceList = dataDictionaryWebService.findEnabledDataValueByEntryId(IMPORTANCE_ENTRYID);
        
        List<UserInfoDTO> userInfoDtos = userManagementWebService.findAllUserInfoHasAccount();
        userInfoDtosJson = JSONArray.fromObject(userInfoDtos).toString()
                .replace("\"", "\\\"");

        flowFormDtos = flowFormWebService.findFlowFormByPage(10, 1,
                new ArrayList<PropertyFilter>(), null).getResult();
        if("task".equals(fromFlag)){
            JobDTO  jobDTO = taskManagementWebService.findJobDetailByJobId(jobId);
            missionDto = jobDTO.getMissionDTO();
            return "TASK";
        }
        if(jobId != null) {
        	JobDTO  jobDTO = taskManagementWebService.findJobDetailByJobId(jobId);
        	reportDetailDTO = reportDataSearchWebService
            .findReportDataInformation(jobDTO.getMissionDTO().getMissionId());
        	return "BACK"; 
        }
        
        return SUCCESS;
    }

    public String getUserInfoDtosJson() {
        return userInfoDtosJson;
    }

    public void setUserInfoDtosJson(String userInfoDtosJson) {
        this.userInfoDtosJson = userInfoDtosJson;
    }
    
    public Long getJobId() {
        return jobId;
    }

    public void setJobId(Long jobId) {
        this.jobId = jobId;
    }

    public List<FlowFormDTO> getFlowFormDtos() {
        return flowFormDtos;
    }

    public void setFlowFormDtos(List<FlowFormDTO> flowFormDtos) {
        this.flowFormDtos = flowFormDtos;
    }

    public List<DataValueDTO> getImportanceList() {
        return importanceList;
    }

    public void setImportanceList(List<DataValueDTO> importanceList) {
        this.importanceList = importanceList;
    }

    public String getFromFlag() {
        return fromFlag;
    }

    public void setFromFlag(String fromFlag) {
        this.fromFlag = fromFlag;
    }

    public MissionDTO getMissionDto() {
        return missionDto;
    }

    public void setMissionDto(MissionDTO missionDto) {
        this.missionDto = missionDto;
    }

	public ReportDetailDTO getReportDetailDTO() {
		return reportDetailDTO;
	}

	public void setReportDetailDTO(ReportDetailDTO reportDetailDTO) {
		this.reportDetailDTO = reportDetailDTO;
	}

    
}
